home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / DrawPart.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  34.6 KB  |  1,165 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawPart.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef DRAWPART_H
  15. #include "DrawPart.h"
  16. #endif
  17.  
  18. #ifndef DRAWDEF_H
  19. #include "DrawDef.h"
  20. #endif
  21.  
  22. #ifndef CONSTANT_H
  23. #include "Constant.h"
  24. #endif
  25.  
  26. #ifndef DRAWFRM_H
  27. #include "DrawFrm.h"
  28. #endif
  29.  
  30. #ifndef DRAWPRXY_H
  31. #include "DrawPrxy.h"
  32. #endif
  33.  
  34. #ifndef BASESHP_H
  35. #include "BaseShp.h"
  36. #endif
  37.  
  38. #ifndef BOUNDSHP_H
  39. #include "BoundShp.h"
  40. #endif
  41.  
  42. #ifndef LINESHP_H
  43. #include "LineShp.h"
  44. #endif
  45.  
  46. #ifndef OVALSHP_H
  47. #include "OvalShp.h"
  48. #endif
  49.  
  50. #ifndef RECTSHP_H
  51. #include "RectShp.h"
  52. #endif
  53.  
  54. #ifndef RRECTSHP_H
  55. #include "RRectShp.h"
  56. #endif
  57.  
  58. #ifndef TEXTSHP_H
  59. #include "TextShp.h"
  60. #endif
  61.  
  62. #ifndef DRAWSEL_H
  63. #include "DrawSel.h"
  64. #endif
  65.  
  66. #ifndef DRAWLINK_H
  67. #include "DrawLink.h"
  68. #endif
  69.  
  70. #ifndef TOOLFRM_H
  71. #include "ToolFrm.h"
  72. #endif
  73.  
  74. #ifndef PALFRAME_H
  75. #include "PalFrame.h"
  76. #endif
  77.  
  78. #ifndef PATFRAME_H
  79. #include "PatFrame.h"
  80. #endif
  81.  
  82. #ifndef DRAWCMDS_H
  83. #include "DrawCmds.h"
  84. #endif
  85.  
  86. #ifndef DRAWCLIP_H
  87. #include "DrawClip.h"
  88. #endif
  89.  
  90. #ifndef SOM_ODFExamples_ODFDrawEmbeddedFramesIterator_xh
  91. #include "SOMIter.xh"
  92. #endif
  93.  
  94. //#ifndef ALGNOBFR_H
  95. //#include "AlgnObFr.h"
  96. //#endif
  97.  
  98. // ----- Part Layer -----
  99.  
  100. #ifndef FWABOUT_H
  101. #include "FWAbout.h"
  102. #endif
  103.  
  104. #ifndef FWUTIL_H
  105. #include "FWUtil.h"
  106. #endif
  107.  
  108. #ifndef FWSCLBAR_H
  109. #include "FWSclBar.h"
  110. #endif
  111.  
  112. #ifndef FWPRESEN_H
  113. #include "FWPresen.h"
  114. #endif
  115.  
  116. // ----- OS Layer -----
  117.  
  118. #ifndef FWRECT_H
  119. #include "FWRect.h"
  120. #endif
  121.  
  122. #ifndef FWRECSHP_H
  123. #include "FWRecShp.h"
  124. #endif
  125.  
  126. #ifndef FWWINDOW_H
  127. #include "FWWindow.h"
  128. #endif
  129.  
  130. #ifndef FWFLOWIN_H
  131. #include "FWFloWin.h"
  132. #endif
  133.  
  134. #ifndef FWEVENT_H
  135. #include "FWEvent.h"
  136. #endif
  137.  
  138. #ifndef FWMENU_H
  139. #include "FWMenu.h"
  140. #endif
  141.  
  142. #ifndef FWODGEOM_H
  143. #include "FWODGeom.h"
  144. #endif
  145.  
  146. #ifndef FWALERT_H
  147. #include "FWAlert.h"
  148. #endif
  149.  
  150. #ifndef FWCFMRES_H
  151. #include "FWCFMRes.h"
  152. #endif
  153.  
  154. // ----- Foundation Includes -----
  155.  
  156. #ifndef FWSTREAM_H
  157. #include "FWStream.h"
  158. #endif
  159.  
  160. #ifndef FWSTRING_H
  161. #include "FWString.h"
  162. #endif
  163.  
  164. #ifndef FWSUSINK_H
  165. #include "FWSUSink.h"
  166. #endif
  167.  
  168. // ----- OpenDoc Includes -----
  169.  
  170. #ifndef SOM_ODArbitrator_xh
  171. #include <Arbitrat.xh>
  172. #endif
  173.  
  174. #ifndef SOM_ODDispatcher_xh
  175. #include <Disptch.xh>
  176. #endif
  177.  
  178. #ifndef SOM_ODShape_xh
  179. #include <Shape.xh>
  180. #endif
  181.  
  182. #ifndef SOM_ODStorageUnit_xh
  183. #include <StorageU.xh>
  184. #endif
  185.  
  186. #ifndef SOM_ODSession_xh
  187. #include <ODSessn.xh>
  188. #endif
  189.  
  190. #ifndef SOM_Module_OpenDoc_StdProps_defined
  191. #include <StdProps.xh>
  192. #endif
  193.  
  194. #ifndef SOM_ODInfo_xh
  195. #include <Info.xh>
  196. #endif
  197.  
  198. //========================================================================================
  199. // Runtime Information
  200. //========================================================================================
  201.  
  202. #ifdef FW_BUILD_MAC
  203. #pragma segment odfdraw
  204. #endif
  205.  
  206. //========================================================================================
  207. //    Globals
  208. //========================================================================================
  209.  
  210. const ODValueType CDrawPart::kPartKind = kODFDrawKind;
  211. const ODValueType CDrawPart::kPartUserName = kODFDrawEditorUserString;
  212.  
  213. //========================================================================================
  214. //    class CDrawPart
  215. //========================================================================================
  216.  
  217. //----------------------------------------------------------------------------------------
  218. //    CDrawPart::CDrawPart
  219. //----------------------------------------------------------------------------------------
  220.  
  221. CDrawPart::CDrawPart(ODPart* odPart) :
  222.     FW_CEmbeddingPart(odPart, CDrawPart::kPartKind, CDrawPart::kPartUserName, FW_gInstance, kPartIconID)
  223. {
  224.     fNbEmbedded = 0;
  225.     
  226.     fShapeList = NULL;
  227.     fCurrentPenSize = FW_IntToFixed(1);
  228.     fRenderVerb = kFillFrame;
  229.     
  230.     fPaletteWindow = NULL;
  231.     fPatternWindow = NULL;
  232.     fToolsWindow = NULL;
  233.  
  234.     fToolFrame = NULL;
  235.     fPaletteFrame = NULL;
  236.     fPatternFrame = NULL;
  237.  
  238.     fPalettePresentation = NULL;
  239.     fPatternPresentation = NULL;
  240.     fToolPresentation = NULL;
  241.     fMainPresentation = NULL;
  242.     fAlignObjectsPresentation = NULL;
  243.     
  244.     fTool = kSelectTool;
  245.     
  246.     fFillColor = FW_kRGBWhite;
  247.     fFrameColor = FW_kRGBBlack;
  248.     
  249.     fAutoGrid = TRUE;
  250.  
  251.     fUnit = cInchUnit;
  252.     fArcUnit = cDegreesUnit;
  253.  
  254.     fPostCreated = FALSE;
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    CDrawPart::~CDrawPart
  259. //----------------------------------------------------------------------------------------
  260.  
  261. CDrawPart::~CDrawPart()
  262. {
  263.     if (fShapeList)
  264.     {
  265.         CBaseShape* shape;
  266.         while ((shape = (CBaseShape*)fShapeList->First()) != NULL)
  267.         {
  268.             fShapeList->Remove(shape);
  269.             delete shape;
  270.         }        
  271.     }
  272.             
  273.     delete fShapeList;
  274. }
  275.  
  276. //----------------------------------------------------------------------------------------
  277. //    CDrawPart::Initialize
  278. //----------------------------------------------------------------------------------------
  279.  
  280. void CDrawPart::Initialize(Environment *ev)
  281. {
  282.     // ----- Call Inherited Initialize -----
  283.     FW_CEmbeddingPart::Initialize(ev);
  284.  
  285.     FW_InitializeArchiving(FW_gInstance);
  286.  
  287.     fShapeList = new FW_CPrivOrderedCollection;
  288.     fDrawingSize.Set(FW_IntToFixed(1024 * 5), FW_IntToFixed(1024 * 5));
  289.  
  290.     InitializeMenuBar(ev, GetMenuBar(ev));
  291.  
  292.     // ----- Tokenize -----
  293.     fDrawSelection = new CDrawSelection(ev, this);    // Attention I don't own the selection the presentation will
  294.     
  295.     fToolPresentation = RegisterPresentation(ev, kToolPresentation, FALSE);
  296.     fPalettePresentation = RegisterPresentation(ev, kPalettePresentation, FALSE);
  297.     fPatternPresentation = RegisterPresentation(ev, kPatternPresentation, FALSE);
  298.     fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, fDrawSelection);
  299.     fAlignObjectsPresentation = RegisterPresentation(ev, kAlignObjectsPresentation, FALSE);
  300.     
  301.     // ----- Pattern Table -----
  302.     fPatternTable[0]     = FW_kBlackPat;
  303.     fPatternTable[1]     = FW_kWhitePat;
  304.     fPatternTable[2]     = FW_kGrayPat;
  305.     fPatternTable[3]     = FW_kLightGrayPat;
  306.     fPatternTable[4]     = FW_kDarkGrayPat;
  307.     fPatternTable[5]     = FW_kHorizontalPat;
  308.     fPatternTable[6]     = FW_kVerticalPat;
  309.     fPatternTable[7]     = FW_kFDiagonalPat;
  310.     fPatternTable[8]     = FW_kBDiagonalPat;
  311.     fPatternTable[9]     = FW_kCrossPat;
  312.     fPatternTable[10]     = FW_kDiagCrossPat;
  313.     fPatternTable[11]     = FW_kAntPat;
  314.     
  315.     fFillPatIndex = 0;
  316.     fFramePatIndex = 0;
  317.     
  318.     SupportFramePaging(ev, TRUE);
  319. }
  320.  
  321. //------------------------------------------------------------------------------
  322. //    CDrawPart::InitializeMenuBar
  323. //------------------------------------------------------------------------------
  324.  
  325. void CDrawPart::InitializeMenuBar(Environment *ev, FW_CMenuBar *menuBar)
  326. {
  327.     FW_CSharedLibraryResourceFile resFile;    // Open the resource file of this shared library
  328.  
  329. #ifdef FW_BUILD_WIN
  330.     // [HLX] Temporary embed menu for windows
  331.     WinAddEmbedMenu(ev, menuBar);
  332. #endif
  333.  
  334.     // ----- Arrange Menu -----
  335.     FW_CPullDownMenu* pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kArrangeStr);
  336.     
  337.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kMoveForwardStr, cMoveForward, 'F');
  338.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kMoveToFrontStr, cMoveToFront);
  339.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kMoveBackwardStr, cMoveBackward, 'B');
  340.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kMoveToBackStr, cMoveToBack);
  341.     pullDownMenu->AppendSeparator(ev);
  342.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kAlignToGridStr, cAlignToGrid);
  343.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kAlignObjectsStr, cAlignObjects);
  344.     pullDownMenu->AppendSeparator(ev);
  345.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kRotateStr, cRotate);
  346.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kFlipHorizontalStr, cFlipH);
  347.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kFlipVerticalStr, cFlipV);
  348.     pullDownMenu->AppendSeparator(ev);
  349.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kGroupStr, cGroup);
  350.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kUngroupStr, cUngroup);
  351.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kLockStr, cLock);
  352.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kUnlockStr, cUnlock);
  353.     menuBar->AdoptMenuLast(ev, pullDownMenu);
  354.  
  355.     // ----- Size Menu -----
  356.     pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kSizeStr);
  357.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k1PixelStr, cPen1);
  358.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k2PixelsStr, cPen2);
  359.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k3PixelsStr, cPen3);
  360.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k4PixelsStr, cPen4);
  361.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k5PixelsStr, cPen5);
  362.     menuBar->AdoptMenuLast(ev, pullDownMenu);
  363.  
  364.     // ----- Options Menu -----
  365.     pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kOptionsStr);
  366.     pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kHideRulersStr, kShowRulersStr, cRulers);
  367.     pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kHideGraphicsGridStr, kShowGraphicsGridStr, cGraphicsGrid);
  368.     pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kTurnAutoGridOnStr, kTurnAutoGridOffStr, cAutoGrid);
  369.     pullDownMenu->AppendSeparator(ev);
  370.         // ----- Unit sub-menu -----
  371.         FW_CPullDownMenu* subMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kUnitsStr);
  372.         subMenu->AppendTextItem(ev, resFile, kMenuStrings, kInchStr, cInchUnit);
  373.         subMenu->AppendTextItem(ev, resFile, kMenuStrings, kCmStr, cCmUnit);
  374.         subMenu->AppendTextItem(ev, resFile, kMenuStrings, kPixelStr, cPixelUnit);
  375.         subMenu->AppendTextItem(ev, resFile, kMenuStrings, kPicaStr, cPicaUnit);
  376.         subMenu->AppendSeparator(ev);
  377.         subMenu->AppendTextItem(ev, resFile, kMenuStrings, kDegreesStr, cDegreesUnit);
  378.         subMenu->AppendTextItem(ev, resFile, kMenuStrings, kRadiansStr, cRadiansUnit);            
  379.     pullDownMenu->AppendSubMenu(ev, subMenu);
  380.     pullDownMenu->AppendSeparator(ev);
  381.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kScaleSelectionStr, cScaleSelection);
  382.     pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kRoundCornersStr, cRoundCorners);
  383.         
  384.     menuBar->AdoptMenuLast(ev, pullDownMenu);
  385.  
  386.     // ----- Windows Menu -----
  387.     pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kWindowsStr);
  388.     pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kShowPaletteStr, kHidePaletteStr, cHideShowPalette);
  389.     pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kShowPatternsStr, kHidePatternsStr, cHideShowPattern);
  390.     pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kShowToolsStr, kHideToolsStr, cHideShowTools);
  391.     menuBar->AdoptMenuLast(ev, pullDownMenu);
  392. }
  393.  
  394. //----------------------------------------------------------------------------------------
  395. //    CDrawPart::InternalizeContent
  396. //----------------------------------------------------------------------------------------
  397.  
  398. void CDrawPart::InternalizeContent(Environment *ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  399. {
  400.     // ----- Create an Archive for our shapes -----
  401.     FW_CStorageUnitSink sink(storageUnit, kODPropContents, this->GetPartKind(ev));
  402.     CDrawReadableStream archive(ev, this, &sink, cloneInfo);
  403.     
  404.     // ----- Read number of shapes -----
  405.     unsigned long count;
  406.     archive >> count;
  407.  
  408.     // ----- Read top left offset -----
  409.     FW_CFixed xTopLeft, yTopLeft;
  410.     archive >> xTopLeft;
  411.     archive >> yTopLeft;
  412.  
  413.     for (short i = 0; i<count; i++)
  414.     {
  415.         CBaseShape* theShape = NULL;
  416.         FW_READ_DYNAMIC_OBJECT(archive, &theShape, CBaseShape);
  417.         FW_ASSERT(theShape);
  418.         
  419.         // ----- Add the shape to the shape list -----
  420.         fShapeList->AddLast(theShape);
  421.                         
  422.         if (xTopLeft || yTopLeft)
  423.         {
  424.             theShape->OffsetShape(ev, -xTopLeft, -yTopLeft);
  425.         }
  426.         theShape->SetExternalizationIndex(i);    // so links can find their shapes
  427.     }
  428.  
  429.     // ----- Read links -----
  430.     CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
  431.     linkMgr->InternalizeLinks(ev, storageUnit);
  432.  
  433.     // ----- Now we have read everything in we can call the facet clipper -----
  434.     CDrawFacetClipper facetClipper(ev, this);
  435.     facetClipper.Clip(ev, fMainPresentation, NULL);
  436.     
  437.     // ----- Read general information -----
  438.     if (storageUnit->Exists(ev, kContentAnnotationProp, (ODValueType)kContentAnnotationValue, 0))
  439.     {
  440.         FW_CStorageUnitSink sink(storageUnit, kContentAnnotationProp, kContentAnnotationValue);
  441.         FW_CReadableStream stream(&sink);
  442.         stream >> fTool;
  443.         stream >> fCurrentPenSize;
  444.         stream >> fRenderVerb;
  445.         stream >> fAutoGrid;
  446.     }
  447. }
  448.  
  449. //----------------------------------------------------------------------------------------
  450. //    CDrawPart::ExternalizeContent
  451. //----------------------------------------------------------------------------------------
  452.  
  453. void CDrawPart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  454. {
  455.     ODValueType contentPropertyValueType = this->GetPartKind(ev);
  456.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, contentPropertyValueType, 0, kODPosUndefined);
  457.     storageUnit->Remove(ev);
  458.     storageUnit->AddValue(ev, contentPropertyValueType);
  459.     
  460.     // ----- Create an archive for our shapes -----
  461.     FW_CStorageUnitSink sink(storageUnit, kODPropContents, contentPropertyValueType);
  462.     CDrawWritableStream archive(ev, &sink, cloneInfo);
  463.     
  464.     // ----- Write number of shapes -----
  465.     unsigned long count = fShapeList->Count();
  466.     archive << count;
  467.     
  468.     // ----- Write top left offset -----
  469.     FW_CFixed offset = FW_IntToFixed(0);
  470.     archive << offset;
  471.     archive << offset;
  472.  
  473.     // ----- Write shapes -----
  474.     short extIndex = 0;    // externalization index, used by links to identify shapes
  475.     FW_COrderedCollectionIterator ite(fShapeList);
  476.     for (CBaseShape* theShape = (CBaseShape*)ite.First(); ite.IsNotComplete(); theShape = (CBaseShape*)ite.Next())
  477.     {
  478.         FW_WRITE_DYNAMIC_OBJECT(archive, theShape, CBaseShape);
  479.         theShape->SetExternalizationIndex(extIndex++);    // so links can write their shapes' indices
  480.     }    
  481.         
  482.     // ----- Write links -----
  483.     CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
  484.     linkMgr->ExternalizeLinks(ev, storageUnit, cloneInfo);
  485.         
  486.     // ----- Write general information -----
  487.     //    FW_SUAddPropValue correctly test if the property and value exist before
  488.     //    trying to create them
  489.     FW_SUAddPropValue(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
  490.  
  491.     FW_CStorageUnitSink sink2(storageUnit, kContentAnnotationProp, kContentAnnotationValue);
  492.     FW_CWritableStream stream(&sink2);
  493.     stream << fTool;
  494.     stream << fCurrentPenSize;
  495.     stream << fRenderVerb;
  496.     stream << fAutoGrid;
  497. }
  498.  
  499. //----------------------------------------------------------------------------------------
  500. //    CDrawPart::NewShape
  501. //----------------------------------------------------------------------------------------
  502.  
  503. CBaseShape* CDrawPart::NewShape(Environment* ev, unsigned short shapeType)
  504. {    
  505.     CBaseShape *theShape = NULL;
  506.  
  507.     FW_ASSERT(shapeType != kProxyShape);        // We should never create a proxyShape this way
  508.     
  509.     switch (shapeType)
  510.     {
  511.         case kLineShape:
  512.             theShape = new CLineShape();
  513.             break;
  514.             
  515.         case kTextShape:
  516.             theShape = new CTextShape();
  517.             break;
  518.         
  519.         case kRectShape:
  520.             theShape = new CRectShape();
  521.             break;
  522.             
  523.         case kOvalShape:
  524.             theShape = new COvalShape();
  525.             break;
  526.             
  527.         case kRRectShape:
  528.             theShape = new CRoundRectShape();
  529.             break;
  530.     }
  531.     
  532.     return theShape;
  533. }
  534.  
  535. //----------------------------------------------------------------------------------------
  536. //    CDrawPart::NewLinkManager
  537. //----------------------------------------------------------------------------------------
  538. FW_CLinkManager* CDrawPart::NewLinkManager(Environment *ev)
  539. {
  540.     CDrawLinkManager* linkMgr = FW_NEW(CDrawLinkManager, (ev, this));
  541.     return linkMgr;
  542. }
  543.  
  544. //----------------------------------------------------------------------------------------
  545. //    CDrawPart::RemoveShape
  546. //----------------------------------------------------------------------------------------
  547. void CDrawPart::RemoveShape(Environment* ev, CBaseShape* shape)
  548. {
  549.     fShapeList->Remove(shape);
  550.     shape->Removed(ev);
  551. }
  552.  
  553. //----------------------------------------------------------------------------------------
  554. //    CDrawPart::DeleteShape
  555. //----------------------------------------------------------------------------------------
  556. void CDrawPart::DeleteShape(Environment* ev, CBaseShape* shape)
  557. {
  558.     fShapeList->Remove(shape);
  559.     shape->Deleted(ev);
  560. }
  561.  
  562. //----------------------------------------------------------------------------------------
  563. //    CDrawPart::AddShape
  564. //----------------------------------------------------------------------------------------
  565. void CDrawPart::AddShape(Environment* ev, CBaseShape* shape)
  566. {
  567.     fShapeList->AddLast(shape);
  568. }
  569.  
  570. //----------------------------------------------------------------------------------------
  571. //    CDrawPart::AddShapeAfter
  572. //----------------------------------------------------------------------------------------
  573. void CDrawPart::AddShapeAfter(Environment* ev, CBaseShape* after, CBaseShape* shape)
  574. {
  575.     fShapeList->AddAfter(after, shape);
  576. }
  577.  
  578. //----------------------------------------------------------------------------------------
  579. //    CDrawPart::DoMenu
  580. //----------------------------------------------------------------------------------------
  581.  
  582. FW_Boolean CDrawPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  583. {
  584.     FW_CString32 name("ODFDraw");
  585.     FW_CString32 sorry("Sorry, not yet implemented!");
  586.  
  587.     FW_Boolean result = TRUE;
  588.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  589.     
  590.     if (cPen1 <= commandID && commandID <= cPen5)
  591.     {
  592.         FW_CFixed penSize = FW_IntToFixed(commandID - cPen1 + 1);
  593.         if (!fDrawSelection->IsEmpty(ev))
  594.             fDrawSelection->ChangeSelectionPenSize(ev, penSize);
  595.         else
  596.             fCurrentPenSize = penSize;
  597.     }
  598.     else
  599.     {
  600.         switch (commandID)
  601.         {
  602. #ifdef FW_BUILD_MAC
  603.             case kODCommandAbout:
  604.                 ::FW_About(FW_gInstance);
  605.                 break;
  606. #endif                
  607.             case cHideShowPattern:
  608.                 if (fPatternWindow == NULL)
  609.                 {
  610.                     FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
  611.                     fPatternWindow = new FW_CFloatingWindow(ev, GetODPart(ev), fPatternPresentation->GetPresentationType(ev), FW_CString32(""), FW_kZeroPoint, position, TRUE);
  612.                 }
  613.                 fPatternWindow->ShowHide(ev, !fPatternWindow->IsShown(ev));
  614.                 break;
  615.                 
  616.             case cHideShowPalette:
  617.                 if (fPaletteWindow == NULL)
  618.                 {
  619.                     FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
  620.                     fPaletteWindow = new FW_CFloatingWindow(ev, GetODPart(ev), fPalettePresentation->GetPresentationType(ev), FW_CString32(""), FW_kZeroPoint, position, TRUE);
  621.                 }
  622.                 fPaletteWindow->ShowHide(ev, !fPaletteWindow->IsShown(ev));
  623.                 break;
  624.             
  625.             case cHideShowTools:
  626.                 if (fToolsWindow == NULL)
  627.                 {
  628.                     FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
  629.                     FW_CPoint windowSize(FW_IntToFixed(kToolsWindowWidth), FW_IntToFixed(kToolsWindowHeight));
  630.                     fToolsWindow = new FW_CFloatingWindow(ev, GetODPart(ev), fToolPresentation->GetPresentationType(ev), FW_CString32(""), windowSize, position, TRUE);
  631.                 }
  632.                 fToolsWindow->ShowHide(ev, !fToolsWindow->IsShown(ev));
  633.                 break;
  634.  
  635.             case cMoveForward:
  636.                 MoveForward(ev);
  637.                 this->Changed(ev);
  638.                 break;
  639.             case cMoveToFront:
  640.                 MoveToFront(ev);
  641.                 this->Changed(ev);
  642.                 break;
  643.             case cMoveBackward:
  644.                 MoveBackward(ev);
  645.                 this->Changed(ev);
  646.                 break;
  647.             case cMoveToBack:
  648.                 MoveToBack(ev);
  649.                 this->Changed(ev);
  650.                 break;
  651.             
  652.             case cAutoGrid:
  653.                 fAutoGrid = !fAutoGrid;
  654.                 break;
  655.  
  656.             case cAlignObjects:
  657. #ifdef FW_DIALOGS_WIP
  658.                 LaunchDialog(ev, fAlignObjectsPresentation, kModalDialog,
  659.                               FW_CPoint(ff(100), ff(100)), FW_CPoint(ff(360), ff(220)));
  660. #endif
  661. //                break;
  662.                 
  663.             case cAlignToGrid:
  664.             case cRotate:
  665.             case cFlipH:
  666.             case cFlipV:
  667.             case cGroup:
  668.             case cUngroup:
  669.             case cLock:
  670.             case cUnlock:
  671.             case cScaleSelection:
  672.             case cRoundCorners:
  673.                 FW_CAlert::DoNote(name, sorry);
  674.                 break;
  675.  
  676.             case cInchUnit:
  677.             case cCmUnit:
  678.             case cPixelUnit:
  679.             case cPicaUnit:
  680.                 fUnit = commandID;
  681.                 break;
  682.                 
  683.             case cDegreesUnit:
  684.             case cRadiansUnit:
  685.                 fArcUnit = commandID;
  686.                 break;
  687.  
  688.             default:
  689.                 result = FALSE;
  690.         }    
  691.     }
  692.     
  693.     return result;
  694. }
  695.  
  696. //----------------------------------------------------------------------------------------
  697. //    CDrawPart::SetTool
  698. //----------------------------------------------------------------------------------------
  699. void CDrawPart::SetTool(Environment* ev, unsigned short newTool)
  700. {
  701.     if (fTool != newTool)
  702.     {
  703.         if (fTool == kSelectTool && !fDrawSelection->IsEmpty(ev))
  704.             fDrawSelection->CloseSelection(ev);
  705.         
  706.         CheckTool(ev, fTool, newTool);
  707.         fTool = newTool;        
  708.     }
  709. }
  710.  
  711. //----------------------------------------------------------------------------------------
  712. //    CDrawPart::SetRenderVerb
  713. //----------------------------------------------------------------------------------------
  714. void CDrawPart::SetRenderVerb(Environment* ev, unsigned short renderVerb)
  715. {
  716.     if (fRenderVerb != renderVerb)
  717.     {        
  718.         if (!fDrawSelection->IsEmpty(ev))
  719.         {
  720.             CChangeRenderVerbCommand* cmd = FW_NEW(CChangeRenderVerbCommand,
  721.                                                     (ev, this, this->GetActiveFrame(ev), fDrawSelection, renderVerb));
  722.             this->ExecuteCommand(ev, cmd);
  723.         }
  724.  
  725.         unsigned short oldRenderVerb = fRenderVerb;
  726.         fRenderVerb = renderVerb;        
  727.         CheckRenderVerb(ev, oldRenderVerb, fRenderVerb);
  728.     }
  729. }
  730.  
  731. //----------------------------------------------------------------------------------------
  732. //    CDrawPart::NewFrame
  733. //----------------------------------------------------------------------------------------
  734. FW_CFrame* CDrawPart::NewFrame(Environment* ev, 
  735.                                 ODFrame* odFrame, 
  736.                                 FW_CPresentation* presentation,
  737.                                 FW_Boolean fromStorage)
  738. {
  739.     if (presentation == fPalettePresentation)
  740.     {
  741.         FW_ASSERT(fPaletteFrame == NULL);
  742.         return (fPaletteFrame = new CPaletteFrame(ev, odFrame, presentation, this));
  743.     }
  744.     else if (presentation == fPatternPresentation)
  745.     {
  746.         FW_ASSERT(fPatternFrame == NULL);
  747.         return (fPatternFrame = new CPatternFrame(ev, odFrame, presentation, this));
  748.     }
  749.     else if (presentation == fToolPresentation)
  750.     {
  751.         FW_ASSERT(fToolFrame == NULL);
  752.         return (fToolFrame = new CToolFrame(ev, odFrame, presentation, this));
  753.     }
  754. //    else if (presentation == fAlignObjectsPresentation)
  755. //    {
  756. //        return FW_NEW(CAlignObjectsFrame, (ev, odFrame, this));
  757. //    }
  758.     
  759.     return new CDrawFrame(ev, odFrame, presentation, this);
  760. }
  761.  
  762. //----------------------------------------------------------------------------------------
  763. //    CDrawPart::DoAdjustMenus
  764. //----------------------------------------------------------------------------------------
  765.  
  766. FW_Boolean CDrawPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  767. {
  768.     if (!hasMenuFocus)
  769.         return FALSE;
  770.         
  771.     ODCommandID command;
  772.     FW_Boolean hasSelection = fDrawSelection->Count() > 0;
  773.  
  774.     // ----- Edit Menu -----
  775.     menuBar->EnableCommand(ev, kODCommandSelectAll, fShapeList->Count() > 0);
  776.     menuBar->SetItemString(ev, kODCommandAbout, FW_CString32("About ODFDraw..."));    // [HLX] Should go into a resource
  777.  
  778.     // ----- PenSize Menu -----
  779.     FW_CFixed penSize = fCurrentPenSize;
  780.     if (fDrawSelection->Count() >= 1)
  781.     {
  782.         if (!fDrawSelection->GetSelectionPenSize(ev, penSize))
  783.         {
  784.             penSize = FW_kFixed0;
  785.         }
  786.     }
  787.     command = penSize.AsInt() + cPen1 - 1;
  788.     
  789.     for (ODCommandID p = cPen1; p <= cPen5; p++)
  790.         menuBar->EnableAndCheckCommand(ev, p, TRUE, p == command);
  791.     
  792.     FW_Boolean readWrite = !IsReadOnly(ev);
  793.     
  794.     // ----- Arrange Menu -----
  795.     menuBar->EnableCommand(ev, cMoveForward, readWrite && hasSelection);
  796.     menuBar->EnableCommand(ev, cMoveToFront, readWrite && hasSelection);
  797.     menuBar->EnableCommand(ev, cMoveBackward, readWrite && hasSelection);
  798.     menuBar->EnableCommand(ev, cMoveToBack, readWrite && hasSelection);
  799.     menuBar->EnableCommand(ev, cAlignToGrid, readWrite && hasSelection);
  800.     menuBar->EnableCommand(ev, cAlignObjects, readWrite && hasSelection);
  801.     menuBar->EnableCommand(ev, cRotate, readWrite && hasSelection);
  802.     menuBar->EnableCommand(ev, cFlipH, readWrite && hasSelection);
  803.     menuBar->EnableCommand(ev, cFlipV, readWrite && hasSelection);
  804.     menuBar->EnableCommand(ev, cGroup, readWrite && hasSelection);
  805.     menuBar->EnableCommand(ev, cUngroup, readWrite && hasSelection);
  806.     menuBar->EnableCommand(ev, cLock, readWrite && hasSelection);
  807.     menuBar->EnableCommand(ev, cUnlock, readWrite && hasSelection);
  808.         
  809.     // ----- Options Menu -----
  810.     menuBar->EnableAndToggleCommand(ev, cAutoGrid, TRUE, !fAutoGrid);
  811.     menuBar->EnableCommand(ev, cScaleSelection, readWrite && hasSelection);
  812.     menuBar->EnableCommand(ev, cRoundCorners, TRUE);
  813.  
  814.     // ----- Units Menu -----
  815.     menuBar->EnableAndCheckCommand(ev, cInchUnit, TRUE, fUnit == cInchUnit);
  816.     menuBar->EnableAndCheckCommand(ev, cCmUnit, TRUE, fUnit == cCmUnit);
  817.     menuBar->EnableAndCheckCommand(ev, cPixelUnit, TRUE, fUnit == cPixelUnit);
  818.     menuBar->EnableAndCheckCommand(ev, cPicaUnit, TRUE, fUnit == cPicaUnit);
  819.     menuBar->EnableAndCheckCommand(ev, cDegreesUnit, TRUE, fArcUnit == cDegreesUnit);
  820.     menuBar->EnableAndCheckCommand(ev, cRadiansUnit, TRUE, fArcUnit == cRadiansUnit);
  821.  
  822.     // ----- Window Menu -----
  823.     menuBar->EnableAndToggleCommand(ev, cHideShowTools, TRUE, fToolsWindow == NULL || !fToolsWindow->IsShown(ev));
  824.     menuBar->EnableAndToggleCommand(ev, cHideShowPalette, TRUE, fPaletteWindow == NULL || !fPaletteWindow->IsShown(ev));
  825.     menuBar->EnableAndToggleCommand(ev, cHideShowPattern, TRUE, fPatternWindow == NULL || !fPatternWindow->IsShown(ev));    
  826.  
  827.     return FALSE;
  828. }
  829.  
  830. //----------------------------------------------------------------------------------------
  831. //    CDrawPart::CheckTool
  832. //----------------------------------------------------------------------------------------
  833.  
  834. void CDrawPart::CheckTool(Environment* ev, unsigned short oldTool, unsigned short newTool)
  835. {
  836.     if (fToolFrame != NULL)
  837.         fToolFrame->CheckTool(ev, oldTool, newTool);
  838. }
  839.  
  840. //----------------------------------------------------------------------------------------
  841. //    CDrawPart::CheckRenderVerb
  842. //----------------------------------------------------------------------------------------
  843.  
  844. void CDrawPart::CheckRenderVerb(Environment* ev, unsigned short oldRenderVerb, unsigned short newRenderVerb)
  845. {
  846.     if (fToolFrame != NULL)
  847.         fToolFrame->CheckRenderVerb(ev, oldRenderVerb, newRenderVerb);
  848. }
  849.  
  850. //----------------------------------------------------------------------------------------
  851. //    CDrawPart::UpdateAfterMove
  852. //----------------------------------------------------------------------------------------
  853.  
  854. void CDrawPart::UpdateAfterMove(Environment* ev)
  855. {
  856.     CDrawFacetClipper facetClipper(ev, this);
  857.     facetClipper.Clip(ev, fMainPresentation, fDrawSelection->GetUpdateShape());
  858.     
  859.     fMainPresentation->Invalidate(ev, fDrawSelection->GetUpdateShape());    
  860. }
  861.  
  862. //----------------------------------------------------------------------------------------
  863. //    CDrawPart::MoveBackward
  864. //----------------------------------------------------------------------------------------
  865.  
  866. void CDrawPart::MoveBackward(Environment* ev)
  867. {
  868.     FW_Boolean didIt = FALSE;
  869.     
  870.     CBaseShape* shape = (CBaseShape*)fShapeList->First();
  871.     CBaseShape* previous = NULL;
  872.     while (shape != NULL)
  873.     {
  874.         if (shape->IsSelectedShape() && previous != NULL && !previous->IsSelectedShape())
  875.         {
  876.             fShapeList->Remove(shape);
  877.             fShapeList->AddBefore(previous, shape);            
  878.             shape->MovedBefore(ev, previous);
  879.             shape = previous;            
  880.             didIt = TRUE;
  881.         }
  882.         else
  883.             previous = shape;
  884.         
  885.         shape = (CBaseShape*)fShapeList->After(shape);
  886.     }
  887.  
  888.     if (didIt)
  889.         UpdateAfterMove(ev);
  890. }
  891.  
  892. //----------------------------------------------------------------------------------------
  893. //    CDrawPart::MoveForward
  894. //----------------------------------------------------------------------------------------
  895.  
  896. void CDrawPart::MoveForward(Environment* ev)
  897. {
  898.     FW_Boolean didIt = FALSE;
  899.     
  900.     CBaseShape* shape = (CBaseShape*)fShapeList->Last();
  901.     CBaseShape* next = NULL;
  902.     while (shape != NULL)
  903.     {
  904.         if (shape->IsSelectedShape() && next != NULL && !next->IsSelectedShape())
  905.         {
  906.             fShapeList->Remove(shape);
  907.             fShapeList->AddAfter(next, shape);            
  908.             shape->MovedAfter(ev, next);
  909.             shape = next;            
  910.             didIt = TRUE;
  911.         }
  912.         else
  913.             next = shape;
  914.             
  915.         shape = (CBaseShape*)fShapeList->Before(shape);
  916.     }
  917.         
  918.     if (didIt)
  919.         UpdateAfterMove(ev);
  920. }
  921.  
  922. //----------------------------------------------------------------------------------------
  923. //    CDrawPart::MoveToBack
  924. //----------------------------------------------------------------------------------------
  925.  
  926. void CDrawPart::MoveToBack(Environment* ev)
  927. {
  928.     FW_CPrivOrderedCollection* extract = ExtractSelection(ev);
  929.  
  930.     FW_TRY
  931.     {        
  932.         FW_COrderedCollectionIterator ite(extract);
  933.         for (CBaseShape* shape = (CBaseShape*)ite.Last(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Previous())
  934.         {
  935.             fShapeList->AddFirst(shape);
  936.             shape->MovedFirst(ev);
  937.         }
  938.     }
  939.     FW_CATCH_BEGIN
  940.     FW_CATCH_EVERYTHING()
  941.     {
  942.         delete extract;    // calls RemoveAll
  943.         
  944.         FW_THROW_SAME();
  945.     }
  946.     FW_CATCH_END
  947.         
  948.     delete extract;    // calls RemoveAll
  949.  
  950.     UpdateAfterMove(ev);
  951. }
  952.  
  953. //----------------------------------------------------------------------------------------
  954. //    CDrawPart::MoveToFront
  955. //----------------------------------------------------------------------------------------
  956.  
  957. void CDrawPart::MoveToFront(Environment* ev)
  958. {
  959.     FW_CPrivOrderedCollection* extract = ExtractSelection(ev);
  960.     
  961.     FW_TRY
  962.     {        
  963.         FW_COrderedCollectionIterator ite(extract);
  964.         for (CBaseShape* shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
  965.         {
  966.             fShapeList->AddLast(shape);
  967.             shape->MovedLast(ev);
  968.         }
  969.     }
  970.     FW_CATCH_BEGIN
  971.     FW_CATCH_EVERYTHING()
  972.     {
  973.         delete extract;    // calls RemoveAll
  974.         
  975.         FW_THROW_SAME();
  976.     }
  977.     FW_CATCH_END
  978.         
  979.     delete extract;    // calls RemoveAll
  980.  
  981.     UpdateAfterMove(ev);
  982. }
  983.  
  984. //----------------------------------------------------------------------------------------
  985. //    CDrawPart::ExtractSelection
  986. //----------------------------------------------------------------------------------------
  987.  
  988. FW_CPrivOrderedCollection* CDrawPart::ExtractSelection(Environment* ev)
  989. {
  990.     FW_CPrivOrderedCollection* extract = new FW_CPrivOrderedCollection;
  991.     
  992.     // ----- Create the extract list -----
  993.     FW_COrderedCollectionIterator ite(fShapeList);
  994.     CBaseShape* shape;
  995.     for (shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
  996.     {
  997.         if (shape->IsSelectedShape())
  998.             extract->AddLast(shape);
  999.     }
  1000.         
  1001.     // ----- Remove then from the shape list -----
  1002.     FW_COrderedCollectionIterator ite2(extract);
  1003.     for (shape = (CBaseShape*)ite2.First(); ite2.IsNotComplete(); shape = (CBaseShape*)ite2.Next())
  1004.     {
  1005.         fShapeList->Remove(shape);
  1006.     }
  1007.     
  1008.     return extract;
  1009. }
  1010.  
  1011. //----------------------------------------------------------------------------------------
  1012. //    CDrawPart::UpdateAllToolFacets
  1013. //----------------------------------------------------------------------------------------
  1014.  
  1015. void CDrawPart::UpdateAllToolFacets(Environment *ev)
  1016. {
  1017.     if (fToolFrame != NULL)
  1018.         fToolFrame->UpdateColors(ev);
  1019. }
  1020.  
  1021. //----------------------------------------------------------------------------------------
  1022. //    CDrawPart::SetFillColor
  1023. //----------------------------------------------------------------------------------------
  1024.  
  1025. void CDrawPart::SetFillColor(Environment *ev, const FW_CColor& color)
  1026. {
  1027.     if (fDrawSelection->IsEmpty(ev))
  1028.     {
  1029.         fFillColor = color;
  1030.         UpdateAllToolFacets(ev);
  1031.     }
  1032.     else if (!fDrawSelection->IsOKtoEdit(ev))
  1033.     {
  1034.         FW_Beep();
  1035.     }
  1036.     else
  1037.     {
  1038.         CChangeColorCommand* cmd = FW_NEW(CChangeColorCommand,
  1039.                                             (ev, cChangeFillColor, this, this->GetActiveFrame(ev), fDrawSelection, color));
  1040.         this->ExecuteCommand(ev, cmd);
  1041.     }
  1042. }
  1043.  
  1044. //----------------------------------------------------------------------------------------
  1045. //    CDrawPart::SetFrameColor
  1046. //----------------------------------------------------------------------------------------
  1047.  
  1048. void CDrawPart::SetFrameColor(Environment *ev, const FW_CColor& color)
  1049. {    
  1050.     if (fDrawSelection->IsEmpty(ev))
  1051.     {
  1052.         fFrameColor = color;
  1053.         UpdateAllToolFacets(ev);
  1054.     }
  1055.     else if (!fDrawSelection->IsOKtoEdit(ev))
  1056.     {
  1057.         FW_Beep();
  1058.     }
  1059.     else
  1060.     {    
  1061.         CChangeColorCommand* cmd = FW_NEW(CChangeColorCommand,
  1062.                                                 (ev, cChangeFrameColor, this, this->GetActiveFrame(ev), fDrawSelection, color));
  1063.         this->ExecuteCommand(ev, cmd);
  1064.     }
  1065. }
  1066.  
  1067. //----------------------------------------------------------------------------------------
  1068. //    CDrawPart::SetFillPattern
  1069. //----------------------------------------------------------------------------------------
  1070.  
  1071. void CDrawPart::SetFillPattern(Environment *ev, short newFillPatIndex)
  1072. {
  1073.     if (fDrawSelection->IsEmpty(ev))
  1074.     {
  1075.         fFillPatIndex = newFillPatIndex;
  1076.         UpdateAllToolFacets(ev);
  1077.     }
  1078.     else if (!fDrawSelection->IsOKtoEdit(ev))
  1079.     {
  1080.         FW_Beep();
  1081.     }
  1082.     else
  1083.     {
  1084.         FW_PPattern pattern = GetPattern(newFillPatIndex)->Copy();
  1085.         CChangePatternCommand* cmd = FW_NEW(CChangePatternCommand,
  1086.                                                 (ev, cChangeFillPattern, this, this->GetActiveFrame(ev), fDrawSelection, pattern));
  1087.         this->ExecuteCommand(ev, cmd);
  1088.     }
  1089. }
  1090.  
  1091. //----------------------------------------------------------------------------------------
  1092. //    CDrawPart::SetFramePattern
  1093. //----------------------------------------------------------------------------------------
  1094.  
  1095. void CDrawPart::SetFramePattern(Environment *ev, short newFramePatIndex)
  1096. {
  1097.     if (fDrawSelection->IsEmpty(ev))
  1098.     {
  1099.         fFramePatIndex = newFramePatIndex;
  1100.         UpdateAllToolFacets(ev);
  1101.     }
  1102.     else if (!fDrawSelection->IsOKtoEdit(ev))
  1103.     {
  1104.         FW_Beep();
  1105.     }
  1106.     else
  1107.     {
  1108.         FW_PPattern pattern = GetPattern(newFramePatIndex)->Copy();
  1109.         CChangePatternCommand* cmd = FW_NEW(CChangePatternCommand,
  1110.                                                     (ev, cChangeFramePattern, this, this->GetActiveFrame(ev), fDrawSelection, pattern));
  1111.         this->ExecuteCommand(ev, cmd);
  1112.     }
  1113. }
  1114.  
  1115. //----------------------------------------------------------------------------------------
  1116. // CDrawPart::WhichShape
  1117. //----------------------------------------------------------------------------------------
  1118.  
  1119. CBaseShape* CDrawPart::WhichShape(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent, FW_Boolean hasToBeSelected) const
  1120. {
  1121.     FW_COrderedCollectionIterator ite(fShapeList);
  1122.     for (CBaseShape* shape = (CBaseShape*)ite.Last(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Previous())
  1123.     {
  1124.         FW_Boolean test = (!hasToBeSelected) || (hasToBeSelected && shape->IsSelectedShape());
  1125.         if (test && shape->HitTest(ev, gc, theMouseEvent))
  1126.             return shape;    
  1127.     }
  1128.     
  1129.     return NULL;
  1130. }
  1131.  
  1132. //----------------------------------------------------------------------------------------
  1133. // CDrawPart::FindShapeWithIndex
  1134. //----------------------------------------------------------------------------------------
  1135. CBaseShape* CDrawPart::FindShapeWithIndex(short extIndex)
  1136. {
  1137.     // Search the shape list and return the shape with the specified externalization index
  1138.     FW_COrderedCollectionIterator ite(fShapeList);
  1139.     for (CBaseShape* shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
  1140.     {
  1141.         if (shape->GetExternalizationIndex() == extIndex)
  1142.             return shape;
  1143.     }    
  1144.  
  1145.     // extIndex not found!?
  1146.     return NULL;
  1147. }
  1148.  
  1149. //----------------------------------------------------------------------------------------
  1150. // CDrawPart::DoPostCreate
  1151. //----------------------------------------------------------------------------------------
  1152. void CDrawPart::DoPostCreate(Environment* ev)
  1153. {
  1154.     // Perform "DoPostCreate"-type initialization.
  1155.     // In our case, we want to make sure that any subscribers that were just internalized 
  1156.     // get registered for automatic updates.
  1157.  
  1158.     if (!fPostCreated)    // do this only once!
  1159.     {
  1160.         CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
  1161.         linkMgr->RegisterSubscribers(ev);
  1162.         fPostCreated = TRUE;
  1163.     }
  1164. }
  1165.